from django.db import models

from lapi_app.models.user_model.user_info import Userinfo


class UI_case(models.Model):
    address = models.TextField("启动的页面地址", null=False, default="")
    value = models.JSONField("执行值", null=False, default=dict)
    '''
    value = [{"name": "每个元素的名称", "xpath": "xpath地址", "iframe":"0不是iframe,1是iframe", 
              "event": "事件类型", "value": "输入值" ,"wait_time":" 等待时间"}]
    '''
    update_time = models.DateTimeField("更新时间", auto_now=True)
    create_time = models.DateTimeField("创建时间", auto_now_add=True)
    user = models.ForeignKey(Userinfo, on_delete=models.CASCADE)

    def __str__(self):
        return self.value


class UI_case_result(models.Model):
    result = models.TextField("执行结果", null=False, default="")
    result_type = models.IntegerField("结果类型", null=False, default=1)  # 1.执行结果， 2.截图
    create_time = models.DateTimeField("创建时间", auto_now_add=True)
    ui = models.ForeignKey(UI_case, on_delete=models.CASCADE)

    def __str__(self):
        return self.result
